# Copyright (c) 2021 Presto Labs Pte. Ltd.
# Author: gekim

from coin2.exchange.product_info import ProductInfoDefault
from coin2.exchange.symbology import SymbologyInfo


def generate():
  mea = 'Spot.Coincheck.v1'
  me = 'Spot.Coincheck'
  default = ProductInfoDefault()
  symbol_info = SymbologyInfo()
  pairs = ["BTC-JPY", "ETC-JPY", "FCT-JPY", "MONA-JPY"]
  price_tick_sizes = {
      "BTC-JPY": 1.0,
      "ETC-JPY": 0.1,
      "FCT-JPY": 0.01,
      "MONA-JPY": 0.01,
  }

  pis = []
  for symbol in pairs:
    symbol_parts = symbol.split("-")
    base = symbol_parts[0]
    quote = symbol_parts[1]
    native_base = symbol_info.norm_to_native_currency(mea, base)
    native_quote = symbol_info.norm_to_native_currency(mea, quote)
    native_symbol = "%s_%s" % (native_base, native_quote)

    pi = dict(
        symbol=symbol,
        base=base,
        quote=quote,
        native_symbol=native_symbol,
        native_base=native_base,
        native_quote=native_quote,
        price_ticksize=price_tick_sizes[symbol],
        qty_ticksize=0.0001,
    )

    pi = {**pi, **default.product_info(me, symbol)}
    pis.append(pi)

  pis = sorted(pis, key=lambda x: x['symbol'])
  return pis


def gen_coin1_constants():
  data = generate()
  data = convert_coin1_constants(data)
  return data


def convert_coin1_constants(data):
  symbol_list = [info['native_symbol'] for info in data]
  quote_currency_list = [info['native_quote'] for info in data]
  base_currency_list = [info['native_base'] for info in data]
  currency_list = base_currency_list + quote_currency_list
  res = {
      'symbol_list': list(set(symbol_list)),
      'base_currency_list': list(set(base_currency_list)),
      'quote_currency_list': list(set(quote_currency_list)),
      'currency_list': list(set(currency_list)),
  }
  return res


if __name__ == "__main__":
  import json
  print(json.dumps(generate(), indent=2))
